<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=10"/>
    <title>SpTemplate</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
    <link href="${basePath}/resources/extjs4/resources/ext-theme-neptune/ext-theme-neptune-all.css" type="text/css"
          rel="stylesheet"/>
    <link href="${basePath}/static/admin/css/base.css" type="text/css" rel="stylesheet"/>
    <script type="text/javascript">
        BASE_URL = "${basePath}"; //
    </script>


    <script type="text/javascript" src="${basePath}/resources/jquery/dist/jquery.min.js"></script>
    <script type="text/javascript" src="${basePath}/resources/extjs4/bootstrap.js"></script>
    <script type="text/javascript" src="${basePath}/resources/extjs4/locale/ext-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${basePath}/resources/extjs4/ux/TabCloseMenu.js"></script>
    <script type="text/javascript" src="${basePath}/static/admin/js/common4.js"></script>
    <script type="text/javascript" src="${basePath}/static/admin/js/xgmm.js"></script>
</head>

<body>
<div id="msg-div">

</div>
</body>
<script type="text/javascript">

    Ext.onReady(function () {
        var store = Ext.create('Ext.data.TreeStore', {
            proxy: {
                type: 'ajax',
                url: "${basePath}/admin/menu.do"
            }
        });
        var tab = Ext.create('Ext.tab.Panel', {
            region: 'center',
            xtype: 'tabpanel',
            defaults: {
                border: false
            },
            items: [
//                {
//                    closable: false,
//                    itemId: 'dashboard',
//                    title: '仪表盘',
//                    html: '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="/admin/partnerReport.do"></iframe>'
//                }
            ],
            plugins: [
                {
                    ptype: 'tabclosemenu',
                    closeTabText: '关闭',
                    closeOthersTabsText: '关闭其他标签',
                    showCloseAll: true,
                    closeAllTabsText: '关闭所有标签'
                }
            ]
        });

        var tree = Ext.create('Ext.tree.Panel', {
            layout: 'fit',
            frame: true,
            region: 'west',
            collapsible: true,
            width: 240,
            title: '当前用户：${session_admin.realName}',
            autoScroll: true,
            store: store,
//                useArrows: true,
            rootVisible: false,
            buttons: ['->', {
                text: '修改密码',
                handler: function () {
                    new ChangePasswordWindow({}).show();
                }
            }, {
                text: '退出登录',
                handler: function () {
                    top.location.href = "logout.do";
                }
            }],
            listeners: {
                itemclick: function (tree, record, item, index, e, eOpts) {
                    e.preventDefault();
                    e.stopPropagation();

                    if (record.get('children')) {  //如果点击的是目录，就return false;
                        return false;
                    }

                    var tabId = record.get("id");
                    var cp = tab.getComponent(tabId);
                    if (!cp) { //第一次打开，构造聊天窗体，读取最近的信息
                        cp = Ext.create('Ext.container.Container', {
                            itemId: tabId,
                            closable: true,
                            title: record.get("text"),
                            layout: 'fit',
                            items: [Ext.create(record.get("id"))]
                        });
                        tab.add(cp);
                    }
                    //切换对话窗口
                    tab.setActiveTab(cp);
                }
            }
        });

        window.tab = tab;
        Ext.create('Ext.container.Viewport', {
            layout: 'border',
            items: [tree, tab]
        });
    });

    /**
     * tab中动态追加panel.
     * @param objJson
     */
    function dynmaicAddTab(objJson) {

        if (objJson) {
            var cp = tab.getComponent(objJson.title);
            if (!cp) {
                objJson.layout = 'border';
//                    objJson.width = '100%';
//                    objJson.height='100%';
                var panel = Ext.create('Ext.panel.Panel', objJson);

                tab.add(panel);
            }
            //切换对话窗口
            tab.setActiveTab(panel);
        }
    }

    /**
     * 关闭当前的tab页面
     */
    function closeCurrentTab() {
        tab.remove(tab.getActiveTab());
    }
</script>
</html>
